﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CMS.BLL;
using CMS.Entity;

public partial class news_msn_BussinessProfile : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            string stock = string.IsNullOrEmpty(Request["stock"]) ? "000001" :Request["stock"];
            DateTime endDate = string.IsNullOrEmpty(Request["enddate"]) ? DateTime.Parse("2011-01-01") : DateTime.Parse(Request["enddate"]);
            YearProfileBLL bll = new YearProfileBLL();
            var c = bll.GetOne(stock, endDate);
            string content = c.Content.Replace(" ", "&nbsp;").Replace(" ", "&nbsp;&nbsp;").Replace("\r\n", "<br/>");
            Localize1.Text = content;
            lblStock.Text = stock;

            BussinessProfileBLL bussinessProfileBll = new BussinessProfileBLL();
            var t= bussinessProfileBll.GetOne(stock, endDate);
            if (t != null)
            {
                txtContent.Text = t.Content;
            }
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(txtContent.Text) || txtContent.Text=="<span style=\"white-space: normal;\"><br /></span>")
        {
            ClientScript.RegisterStartupScript(GetType(), "aa", "alert('内容不能为空')", true);
            return;
        }
        string stock=Request["stock"];
        DateTime enddate=DateTime.Parse(Request["enddate"]);
        BussinessProfileBLL bll = new BussinessProfileBLL();        
        var c= bll.GetOne(stock, enddate);
        if (c != null)
        {
            c.Content = txtContent.Text;
            bll.Update(c);
        }
        else
        {
            c = new BussinessProfile();
            c.Content = txtContent.Text;
            c.EndDate = enddate;
            c.RecTime = DateTime.Now;
            c.Stock = stock;
            bll.Add(c);
            YearProfileBLL yearBll = new YearProfileBLL();
            var c2= yearBll.GetOne(stock, enddate);
            c2.ModTime = DateTime.Now;
            c2.BussinessProfileFlag = true;
            yearBll.Update(c2);
        }
    }
}